<template>
  <drag-dialog v-model="visible" :title="pdfTitle" :width="width">
    <vue-office-pdf v-if="pdfSource" :src="pdfSource" />
    <el-empty v-else />
    <template #footer>
      <dialog-footer :showCancle="false" ok-text="关闭" @ok="visible = false" />
    </template>
  </drag-dialog>
</template>

<script>
import VueOfficePdf from '@vue-office/pdf';

export default {
  name: 'PdfViewer',
  components: {
    VueOfficePdf
  },
  inheritAttrs: false,
  props: {
    modelValue: {
      type: String,
      default: ''
    },
    width: {
      type: Number,
      default: 800
    },
    pdfTitle: {
      type: String,
      default: 'pdf预览'
    }
  },
  data() {
    return {
      visible: false,
      pdfSource: ''
    };
  },
  watch: {
    modelValue: {
      handler(newVal) {
        if (newVal) {
          this.pdfSource = newVal;
        }
      },
      immediate: true
    }
  },
  methods: {
    open() {
      this.visible = true;
    }
  }
};
</script>